<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">活动编号</label>
        <el-input v-model="query.activityId" clearable placeholder="活动编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">活动平台</label>
        <el-input v-model="query.plat" clearable placeholder="活动平台" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">是否隐藏地址</label>
        <el-input v-model="query.hide" clearable placeholder="是否隐藏地址" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">是否展示</label>
        <el-input v-model="query.show" clearable placeholder="是否展示" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <date-range-picker
          v-model="query.createTime"
          start-placeholder="createTimeStart"
          end-placeholder="createTimeStart"
          @blur="onTimeChange"
          class="date-item"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="'活动链接发布'" width="1000px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="250px">
          <el-form-item label="活动编号" prop="activityId">
            <el-input v-model="form.activityId" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="链接名称"  prop="shuoming">
            <el-input v-model="form.shuoming" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="主链接（真实需要隐藏的链接）">
            <el-input v-model="form.mianUrl" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="是否隐藏地址" prop="hide">
            <el-radio v-model="form.hide" v-for="item in dict.yn" :key="item.id" :label="item.value">{{ item.label }}</el-radio>
          </el-form-item>
          <!--<el-form-item label="访问地址">
            <el-input v-model="form.hideUrl" style="width: 370px;" />
          </el-form-item>-->
          <el-form-item label="链接开始时间">
            <el-date-picker v-model="form.startTime" type="datetime" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="链接结束时间">
            <el-date-picker v-model="form.endTime" type="datetime" style="width: 520px;" />
          </el-form-item>
          <!--<el-form-item label="最后更新时间">
            <el-date-picker v-model="form.lastUpdateTime" type="datetime" style="width: 370px;" />
          </el-form-item>-->

          <el-form-item label="备注1">
            <el-input v-model="form.extra1" style="width: 520px;" />
          </el-form-item>
          <el-form-item label="备注2">
            <el-input v-model="form.extra2" style="width: 520px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="地址编号" />
        <el-table-column prop="activityId" label="活动编号" />
        <el-table-column prop="shuoming" label="链接名称" />
        <el-table-column prop="mianUrl" label="主链接" />
        <el-table-column prop="hide" label="是否隐藏地址">
          <template slot-scope="scope">
            {{ dict.label.yn[scope.row.hide] }}
          </template>
        </el-table-column>
        <el-table-column prop="hideUrl" label="访问地址" />
        <el-table-column prop="startTime" label="链接开始时间" />
        <el-table-column prop="endTime" label="链接结束时间" />
        <el-table-column prop="lastUpdateTime" label="最后更新时间" />
        <el-table-column prop="extra1" label="备注1" />
        <el-table-column prop="extra2" label="备注2" />
        <el-table-column v-if="checkPer(['admin','activityUrl:edit','activityUrl:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudActivityUrl from '@/api/activity/activityUrl'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, activityId: null, mianUrl: null, hide: null, hideUrl: null, startTime: null, endTime: null, lastUpdateTime: null, shuoming: null, extra1: null, extra2: null }
export default {
  name: 'ActivityUrl',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['yn'],
  cruds() {
    return CRUD({ title: 'activityUrl', url: 'api/activityUrl', idField: 'id', sort: 'id,desc', crudMethod: { ...crudActivityUrl }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'activityUrl:add'],
        edit: ['admin', 'activityUrl:edit'],
        del: ['admin', 'activityUrl:del']
      },
      rules: {
        id: [
          { required: true, message: '地址编号不能为空', trigger: 'blur' }
        ],
        activityId: [
          { required: true, message: '活动编号不能为空', trigger: 'blur' }
        ],
        shuoming: [
          { required: true, message: '链接名称不能为空', trigger: 'blur' }
        ],
        hide: [
          { required: true, message: '是否隐藏地址不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'activityId', display_name: '活动编号' },
        { key: 'hide', display_name: '是否隐藏地址' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
